package fr.dsax.nounet.belote.jpa;

import java.io.Serializable;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Entity implementation class for Entity: GameScore
 *
 */
@Entity
@Table(name="game_score")
public class GameScore implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer score;
	
	@EmbeddedId
	@AssociationOverrides({
		@AssociationOverride(name="team", joinColumns = {@JoinColumn(name="id_team")}),
		@AssociationOverride(name="game", joinColumns = @JoinColumn(name="id_game")) 
		})
	private GameScorePk pk;
	
	public GameScore() {
		super();
	}
	
	public GameScorePk getPk() {
		if(pk == null) {
			pk = new GameScorePk();
		}
		return pk;
	}

	public void setPk(GameScorePk id) {
		this.pk = id;
	}

	@Transient
	public Team getTeam() {
		return getPk().getTeam();
	}
	
	public void setTeam(Team team) {
		getPk().setTeam(team);
	}
	
	@Transient
public Game getGame() {
		return getPk().getGame();
	}

	public void setGame(Game game) {
		getPk().setGame(game);
	}
   
	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	@Override
	 public int hashCode() {
        return (getPk() != null ? getPk().hashCode() : 0);
    }

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GameScore other = (GameScore) obj;
		if (pk == null) {
			if (other.pk != null)
				return false;
		} else if (!pk.equals(other.pk))
			return false;
		return true;
	}
	
	
}
